package com.ygxsk.carhome.ui.evaluate;

import android.Manifest;
import android.os.Build;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import androidx.annotation.NonNull;

import com.blankj.utilcode.util.ActivityUtils;
import com.blankj.utilcode.util.AppUtils;
import com.blankj.utilcode.util.KeyboardUtils;
import com.blankj.utilcode.util.NetworkUtils;
import com.blankj.utilcode.util.StringUtils;
import com.blankj.utilcode.util.TimeUtils;
import com.blankj.utilcode.util.ToastUtils;
import com.flyco.roundview.RoundTextView;
import com.gyf.immersionbar.ImmersionBar;
import com.hjq.permissions.OnPermissionCallback;
import com.hjq.permissions.XXPermissions;
import com.hjq.toast.Toaster;
import com.tencent.mmkv.MMKV;
import com.trello.rxlifecycle4.android.ActivityEvent;
import com.ygxsk.carhome.R;
import com.ygxsk.carhome.constant.ConstantApi;
import com.ygxsk.carhome.constant.ConstantSign;
import com.ygxsk.carhome.constant.ExtraKey;
import com.ygxsk.carhome.constant.ExtraValue;
import com.ygxsk.carhome.enumwrap.CallHistoryBusinessType;
import com.ygxsk.carhome.enumwrap.EvaluteCarEstimateType;
import com.ygxsk.carhome.enumwrap.EvalutePriceType;
import com.ygxsk.carhome.event.EventCarEvaluateDetail;
import com.ygxsk.carhome.listener.AuthorityCallbackListener;
import com.ygxsk.carhome.listener.Delivery;
import com.ygxsk.carhome.listener.ErrorParentExtraSingle;
import com.ygxsk.carhome.response.EvaluateDetailItemBean;
import com.ygxsk.carhome.response.EvaluteCurrentItemBean;
import com.ygxsk.carhome.retrofit.AddLogUpLoadInfo;
import com.ygxsk.carhome.retrofit.ApiException;
import com.ygxsk.carhome.retrofit.ApiRequestSubListener;
import com.ygxsk.carhome.retrofit.ApiService;
import com.ygxsk.carhome.retrofit.ErrorConsumer;
import com.ygxsk.carhome.retrofit.NetworkManager;
import com.ygxsk.carhome.retrofit.ResponseTransformer;
import com.ygxsk.carhome.sys.PermissionInterceptor;
import com.ygxsk.carhome.sys.PermissionNameConvert;
import com.ygxsk.carhome.ui.ErrorActivity;
import com.ygxsk.carhome.utils.CommTools;
import com.ygxsk.carhome.utils.CommUtils;
import com.ygxsk.carhome.utils.StringCodeUtils;
import com.ygxsk.carhome.utils.TimeUtilSer;
import com.ygxsk.integrated.retrofit.Parameterkey;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;

import butterknife.BindView;
import cn.bingoogolapple.photopicker.widget.BGANinePhotoLayout;
import io.reactivex.rxjava3.functions.Consumer;
import pub.devrel.easypermissions.AfterPermissionGranted;
import pub.devrel.easypermissions.EasyPermissions;

/*
 * @Author:itchenqi175@163.com
 * @Time:2023-07-17  16:45
 * @Description:到店评估的 详情逻辑，这里涉及到 评估的内容的修改或者补充；车辆评估-右上角-【历史记录】的主列表进来的日历，是没有选择日历的能力的；
 */
public class CarEvaluateDetailActivity extends ErrorActivity implements ErrorParentExtraSingle, EasyPermissions.PermissionCallbacks {

    //该页面仅仅只有预览的能力
    private static final int PRC_PHOTO_PREVIEW = 1;

    //---------顶部用户信息或者车辆信息-----------------------------------------------
    //2023-8-26 10:04:55 新增需求
    @BindView(R.id.roundtextviewinevaluatedetright)
    RoundTextView roundTextViewInEvaluateDetRight;

    //客户姓名
    @BindView(R.id.textviewpersonnametop)
    TextView textViewPersonNameTop;

    //客户手机号
    @BindView(R.id.textviewpersoncallnumber)
    TextView textViewpPersonCallNumber;

    //评估类型
    @BindView(R.id.textviewevaluatetypedetail)
    TextView textViewEvaluateTypeDetail;

    //车型
    @BindView(R.id.textviewpersoncarmodel)
    TextView textViewpPersonCarModel;

    //看车地址的外部包裹
    @BindView(R.id.linearlayoutlookcaraddressdetailtop)
    RelativeLayout linearLayoutLookCarAddressDetailTop;

    //看车时间-外部包裹
    @BindView(R.id.linelayoutdetailcarlooktime)
    RelativeLayout lineLayoutDetailCarLookTime;

    //看车时间 值填充
    @BindView(R.id.textviewdetaillookcartime)
    TextView textViewDetailLookCarTime;

    //看车地址
    @BindView(R.id.textviewpersonlookcaraddress)
    TextView textViewPersonLookCarAddressTop;

    //界面之中的填充：如果是用户-在线评估，那么用户上传的图片要展示出来
    //图片查看的外侧包裹
    @BindView(R.id.linearlayoutmoment_photos)
    LinearLayout linearLayoutMomentPhotos;

    @BindView(R.id.npl_item_moment_photos_in_detail_top)
    BGANinePhotoLayout npl_item_moment_photos_in_detail_top;

    //---------中间评估信息-----------------------------------------------
    //车辆的品牌
    @BindView(R.id.editviewbrandname)
    TextView editViewBrandName;

    //车辆车系
    @BindView(R.id.editviewcarbrandline)
    TextView editViewCarBrandLine;

    //车辆型号-也即是车辆名称
    @BindView(R.id.editviewcarbrandmodel)
    TextView editViewCarBrandModel;

    //跟进状态
//    @BindView(R.id.textvieweditfollowup)
//    TextView textViewEditFollowUp;

    //车辆出厂日期
    @BindView(R.id.textviewstarttimeinworkbook)
    TextView textViewStartTimeInWorkBook;

    //车辆的公里数
    @BindView(R.id.editviewcarmileoutside)
    TextView editViewCarMileOutSide;

    //车辆的颜色
    @BindView(R.id.textviewcolor)
    TextView textViewColor;

    //车辆的事故信息
    @BindView(R.id.textviewcarincidentoutside)
    TextView textViewCarInCidentOutSide;

    //车辆的涉水信息
    @BindView(R.id.textviewcarinwadeoutside)
    TextView textViewCarInWadeOutSide;

    //车辆的备注信息 中间模块的
    @BindView(R.id.textvieweeditinputremark)
    TextView textViewEditInputRemark;

    //中间携带用户备注下方附件还有图片信息也是只能查看不可编辑的：
    @BindView(R.id.npl_item_moment_photos_in_detail_middle)
    BGANinePhotoLayout npl_item_moment_photos_in_detail_middle;


    //---------底部评估价格的信息-----------------------------------------------
    //报价类型
    @BindView(R.id.textvieweditviewformwherename)
    TextView textViewEditViewFormWhereName;

    //评估的价格
    @BindView(R.id.editviewpriceevaluate)
    TextView editViewPriceEvaluate;

    //备注信息取代九宫格
    @BindView(R.id.textvieweevaluatepricebottom)
    TextView textVieweEvaluatePriceBottom;

    //底部的车辆评估的九宫格图片 废弃不用，用备注代替；
//    @BindView(R.id.npl_item_moment_photos_in_detail_bottom)
//    BGANinePhotoLayout npl_item_moment_photos_in_detail_bottom;

    //-----------------------------------------------------------------------------------------------
    //评估详情的外部值；可能有些赋值需要
    private EvaluateDetailItemBean evaluateDetailItemBeanOutSide;
    private EvaluteCurrentItemBean extra_evalute_current_item_bean;

    //这条评估记录的id;
    private String estimateId_upLoad;

    //当前的这个九宫格图片信息
    private BGANinePhotoLayout mCurrentClickNpl;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        mActivityInstance = this;

        processExtraData();

//        initloading();

        initViews();

        gainDatas();

        if (!EventBus.getDefault().isRegistered(this)) {
            EventBus.getDefault().register(this);
        }

    }


    @Override
    protected void initImmersionBar() {
        super.initImmersionBar();

        ImmersionBar.with(this)//
                .titleBar(R.id.toolbarygxskout)
                .fitsSystemWindows(true)//解决状态栏和布局重叠问题，任选其一，默认为false，当为true时一定要指定statusBarColor()，不然状态栏为透明色，还有一些重载方法
                //.statusBarColor(R.color.colorPrimary)//
                //.navigationBarColor(R.color.colorPrimary)//
                //.keyboardEnable(true)
                .init();

    }

    @Override
    protected int getContentViewId() {
        return R.layout.activity_car_evaluate_detail;
    }

    @Override
    protected void initToolBar(ToolbarHelper toolbarHelper) {

//        toolbarHelper.setVersionName(true, AppUtils.getAppVersionName());
        toolbarHelper.setTitle(getString(R.string.carevaluatedetail));
        toolbarHelper.setVersionName(true, AppUtils.getAppVersionName());
        toolbarHelper.setLayoutClose(false, "", null);

        toolbarHelper.setLayoutLeft(true, R.drawable.backicon, new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //搜索客户信息，优先关闭软键盘
                KeyboardUtils.hideSoftInput(mActivityInstance);
                methodBack();
            }
        });

        //应该是 还没有【被分配】被评估完毕的，还是可以再次编辑的
        // : 2023-07-18 11:34 判断该订单的状态，是可以对整个表单再次编辑的
        toolbarHelper.setLayoutRight(false, 0, "", null);

//        toolbarHelper.setLayoutRight(false, 0, "编辑", new ClickUtils.OnDebouncingClickListener() {
//            @Override
//            public void onDebouncingClick(View v) {
//                //历史记录的页面布局
//                Bundle extra_bundle = new Bundle();
//                //这里空携带,,编辑信息 ？
//                ActivityUtils.startActivity(extra_bundle, CarEvaluateAddSubmitActivity.class);
//
//            }
//        });

    }

    @Override
    protected void onClickNodata(View v) {

        gainDatas();

    }

    @Override
    protected void initViews() {

        //填充图片
        //修改 这个详情信息
        if (roundTextViewInEvaluateDetRight != null) {
            roundTextViewInEvaluateDetRight.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {

                    Bundle extra_bundle = new Bundle();

                    //这里先知道了状态，判断哪种状态再填充；，因为涉及到【修改后提交】
                    String estimateType = evaluateDetailItemBeanOutSide.getEstimateType();
                    //String estimateTypeName = evaluateDetailItemBeanOutSide.getEstimateTypeName();

                    if (TextUtils.equals(estimateType, EvaluteCarEstimateType.ESTIMATE_TYPE_ONSTORE.getIndex())) {
                        //到店评估，
                        //跳转到提交页，但是携带基础信息，并填充输入框等；
                        extra_bundle.putString(ExtraKey.EXTRA_JUMPFROM_WHERE_TYPE, EvaluteCarEstimateType.ESTIMATE_TYPE_ONSTORE.getIndex()); //
                        extra_bundle.putString(ExtraKey.EXTRA_EVALUATE_ADD_SUBMIT_TYPE, EvaluteCarEstimateType.ESTIMATE_TYPE_ONSTORE.getValue());//

                    } else if (TextUtils.equals(estimateType, EvaluteCarEstimateType.ESTIMATE_TYPE_ONDOOR.getIndex())) {
                        //上门评估
                        extra_bundle.putString(ExtraKey.EXTRA_JUMPFROM_WHERE_TYPE, EvaluteCarEstimateType.ESTIMATE_TYPE_ONDOOR.getIndex()); //上门评估
                        extra_bundle.putString(ExtraKey.EXTRA_EVALUATE_ADD_SUBMIT_TYPE, EvaluteCarEstimateType.ESTIMATE_TYPE_ONDOOR.getValue());//

                    } else if (TextUtils.equals(estimateType, EvaluteCarEstimateType.ESTIMATE_TYPE_ONLINE.getIndex())) {
                        //在线评估
                        extra_bundle.putString(ExtraKey.EXTRA_JUMPFROM_WHERE_TYPE, EvaluteCarEstimateType.ESTIMATE_TYPE_ONLINE.getIndex()); //在线评估
                        extra_bundle.putString(ExtraKey.EXTRA_EVALUATE_ADD_SUBMIT_TYPE, EvaluteCarEstimateType.ESTIMATE_TYPE_ONLINE.getValue());//

                    } else if (TextUtils.equals(estimateType, EvaluteCarEstimateType.ESTIMATE_TYPE_BOOKING.getIndex())) {
                        //预约评估
                        extra_bundle.putString(ExtraKey.EXTRA_JUMPFROM_WHERE_TYPE, EvaluteCarEstimateType.ESTIMATE_TYPE_BOOKING.getIndex()); //预约评估
                        extra_bundle.putString(ExtraKey.EXTRA_EVALUATE_ADD_SUBMIT_TYPE, EvaluteCarEstimateType.ESTIMATE_TYPE_BOOKING.getValue());//

                    }

                    //将条目的值内容，再次携带回来；
                    extra_bundle.putParcelable(ExtraKey.EXTRA_EVALUTE_CURRENT_ITEM_BEAN, extra_evalute_current_item_bean);//

                    //携带详情信息，主要取出：车辆品牌和车系等，填充真数据用
                    extra_bundle.putParcelable(ExtraKey.EXTRA_EVALUTE_CURRENT_EVALUATE_DETAIL_ITEM_BEAN_OUTSIDE, evaluateDetailItemBeanOutSide);//

                    //标志 是编辑 信息 过去的
                    extra_bundle.putBoolean(ExtraKey.EXTRA_EVALUATE_DETAIL_IS_EDIT, true);

                    ActivityUtils.startActivity(extra_bundle, CarEvaluateAddSubmitActivity.class);

                }
            });
        }
    }

    @Override
    protected void gainDatas() {

        if (NetworkUtils.isConnected()) {

            gainDatasFromServer();

        } else {
            //遮盖信息
            netWorkError();
        }

    }

    private void gainDatasFromServer() {

        estimateId_upLoad = extra_evalute_current_item_bean.getEstimateId();

        HashMap<String, Object> map = new HashMap<>();
        map.put(Parameterkey.estimateId, estimateId_upLoad);

        AddLogUpLoadInfo addLogUpLoadInfo = new AddLogUpLoadInfo();
        addLogUpLoadInfo.setActivity(mActivityInstance);
        addLogUpLoadInfo.setWhat(ConstantApi.WHAT_ESTIMATE_GETBYID);//请求数字标识
        addLogUpLoadInfo.setUrlPath(ApiService.estimate_getById_url);//url地址
        addLogUpLoadInfo.setRequestMethod(ConstantSign.REQUEST_METHOD_GET);//POST 或者 GET
        addLogUpLoadInfo.setToastToUser(true);//展示给用户的标志
        addLogUpLoadInfo.setHashMapParameter(map);

        NetworkManager.getInstance().initRetrofitRxJava()
                .create(ApiService.class)
                //.getById(RequestBody.create(JSON.toJSONString(map, SerializerFeature.PrettyFormat, SerializerFeature.WriteMapNullValue), MediaType.parse(ApiService.HEADER_JSON)))
                .estimate_getById(estimateId_upLoad)
                .compose(CarEvaluateDetailActivity.this.bindUntilEvent(ActivityEvent.DESTROY))
                .compose(new ResponseTransformer<>(addLogUpLoadInfo, new ApiRequestSubListener<EvaluateDetailItemBean>() {
                    @Override
                    public void handlerSomeThingNotSuccessDataForItSelf(int what_method, String serverCode, String serverMessage) {
                        super.handlerSomeThingNotSuccessDataForItSelf(what_method, serverCode, serverMessage);

                        //如果出问题这里要遮盖
                        if (!TextUtils.isEmpty(serverMessage)) {
                            ToastUtils.showShort(serverMessage);
                        }

                    }
                })).subscribe(new Consumer<EvaluateDetailItemBean>() {
                    @Override
                    public void accept(EvaluateDetailItemBean evaluateDetailItemBean) throws Throwable {

                        //主要是顶部变动
                        if (evaluateDetailItemBean != null) {
                            evaluateDetailItemBeanOutSide = evaluateDetailItemBean;
                            methodHandlerSuccess(evaluateDetailItemBean);
                        }

                    }
                }, new ErrorConsumer() {

                    @Override
                    protected void error(ApiException apiException) {

                        //
                    }
                });
    }

    private void methodHandlerSuccess(EvaluateDetailItemBean _evaluateDetailItemBean) {

        Delivery.getInstance().post(new Runnable() {
            @Override
            public void run() {

                //-必填，必展示的------------------------------------------------------------------------------------------
                // 客户姓名
                if (textViewPersonNameTop != null) {
                    CommUtils.setText(textViewPersonNameTop, _evaluateDetailItemBean.getCustomerName());
                }

                //客户手机号
                if (textViewpPersonCallNumber != null) {

//                    CommUtils.setText(textViewpPersonCallNumber, StringCodeUtils.mobileEncrypt(_evaluateDetailItemBean.getCustomerPhone()));
                    CommUtils.setText(textViewpPersonCallNumber, StringCodeUtils.mobileEncrypt(_evaluateDetailItemBean.getCustomerPhone()));

                    textViewpPersonCallNumber.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            clickButton_toCallPhone(CarEvaluateDetailActivity.this, _evaluateDetailItemBean.getCustomerPhone(), CallHistoryBusinessType.BUSINESSTYPE_4.getIndex());
                        }
                    });
                }

                //-------------------------------------------------------------------------------------------
                // : 2023-08-10 10:38 获取评估的类型，不同类型是：看车地址+图片有显示或者隐藏
                //评估类型的【数字格式】
                String estimateType = _evaluateDetailItemBean.getEstimateType();
                //评估类型 汉字格式
                String estimateTypeName = _evaluateDetailItemBean.getEstimateTypeName();
                CommUtils.setText(textViewEvaluateTypeDetail, estimateTypeName);

                //车辆车型 是合并的:特别注意： carBrandName、carSeriesName、vehicleName是小程序端提交的信息；
                //车辆品牌
                String carBrandName = _evaluateDetailItemBean.getCarBrandName();
                //车辆车系
                String carSeriesName = _evaluateDetailItemBean.getCarSeriesName();
                //车辆车型
                String vehicleName = _evaluateDetailItemBean.getVehicleName();

                //车型 是合并的
                CommUtils.setText(textViewpPersonCarModel, carBrandName + getString(R.string.kongge0) + carSeriesName + getString(R.string.kongge0) + vehicleName);

                if (TextUtils.equals(estimateType, EvaluteCarEstimateType.ESTIMATE_TYPE_ONLINE.getIndex())) {

                    //在线评估--地址隐藏--九宫格图片显示
                    CommUtils.setViewGone(linearLayoutLookCarAddressDetailTop);
                    CommUtils.setViewVisible(linearLayoutMomentPhotos);

                    npl_item_moment_photos_in_detail_top.setDelegate(new BGANinePhotoLayout.Delegate() {

                        @Override
                        public void onClickNinePhotoItem(BGANinePhotoLayout ninePhotoLayout, View view, int position, String model, List<String> models) {
                            //点击九宫格,查看大图
                            mCurrentClickNpl = ninePhotoLayout;
                            photoPreviewWrapper();
                        }

                        @Override
                        public void onClickExpand(BGANinePhotoLayout ninePhotoLayout, View view, int position, String model, List<String> models) {
                            //点击展开的
                            ninePhotoLayout.setIsExpand(true);
                            ninePhotoLayout.flushItems();
                        }

                    });

                    npl_item_moment_photos_in_detail_top.setData((ArrayList<String>) _evaluateDetailItemBean.getCustomerImgs());

                } else if (TextUtils.equals(estimateType, EvaluteCarEstimateType.ESTIMATE_TYPE_BOOKING.getIndex())) {

                    //预约评估--地址隐藏--九宫格图片隐藏
                    CommUtils.setViewGone(linearLayoutLookCarAddressDetailTop);
                    CommUtils.setViewGone(linearLayoutMomentPhotos);

                } else if (TextUtils.equals(estimateType, EvaluteCarEstimateType.ESTIMATE_TYPE_ONDOOR.getIndex())) {

                    //上门评估--有看车地址--看车时间-九宫格隐藏
                    CommUtils.setViewVisible(linearLayoutLookCarAddressDetailTop);
                    CommUtils.setViewVisible(lineLayoutDetailCarLookTime);
                    CommUtils.setViewGone(linearLayoutMomentPhotos);
                    //看车地址:这个根据类型 如果是上门评估 是有看车地址的；
                    CommUtils.setText(textViewPersonLookCarAddressTop, _evaluateDetailItemBean.getAddress());
                    //看车时间
                    CommUtils.setText(textViewDetailLookCarTime, _evaluateDetailItemBean.getDoorTime());

                } else if (TextUtils.equals(estimateType, EvaluteCarEstimateType.ESTIMATE_TYPE_ONSTORE.getIndex())) {

                    //到店评估 --地址隐藏--九宫格图片隐藏
                    CommUtils.setViewGone(linearLayoutLookCarAddressDetailTop);
                    //看车时间隐藏
                    CommUtils.setViewGone(lineLayoutDetailCarLookTime);
                    //九宫格隐藏
                    CommUtils.setViewGone(linearLayoutMomentPhotos);

                }

                //----------------------------------------------------------------------------------------------------
                //中间的信息模块：这是员工提交的信息，采用和顶部不一样的字段；
                //车辆品牌
                CommUtils.setText(editViewBrandName, _evaluateDetailItemBean.getBrandName());
                //车辆车系
                CommUtils.setText(editViewCarBrandLine, _evaluateDetailItemBean.getSeriesName());
                //车辆型号
                CommUtils.setText(editViewCarBrandModel, _evaluateDetailItemBean.getCarName());

                //车辆的出厂日期： "releaseDate": "2023-08-10 00:00:00",
                //车辆出厂日期，2024-2-27 应了苹果端的要求给的是短时间。所以这里做判断，如果是长时间就改造为短时间，如果是短时间就放过
                if (!TextUtils.isEmpty(_evaluateDetailItemBean.getReleaseDate())) {

                    if (_evaluateDetailItemBean.getReleaseDate().length() > TimeUtilSer.simplemore.length()) {

                        Date date = TimeUtils.string2Date(_evaluateDetailItemBean.getReleaseDate());
                        String resultDate = TimeUtils.date2String(date, TimeUtilSer.simplemore);
                        //时间 格式化：
                        CommUtils.setText(textViewStartTimeInWorkBook, resultDate);

                    } else {
                        CommUtils.setText(textViewStartTimeInWorkBook, _evaluateDetailItemBean.getReleaseDate());
                    }

                } else {
                    //填充空值
                    CommUtils.setText(textViewStartTimeInWorkBook, "");
                }

                //车辆的公里数
                String mileage = "";
                if (_evaluateDetailItemBean.getMileage() != null) {
                    mileage = _evaluateDetailItemBean.getMileage().toString();
                } else {
                    mileage = CommUtils.formatComma2BigDecimal("0.00").toString();
                }
                CommUtils.setText(editViewCarMileOutSide, mileage);

                //车辆的颜色
                CommUtils.setText(textViewColor, _evaluateDetailItemBean.getCarColor());

                //车辆的事故信息，仅仅给的是标识 accident,或者文字信息
                //String accident = _evaluateDetailItemBean.getAccidentName();
                CommUtils.setText(textViewCarInCidentOutSide, _evaluateDetailItemBean.getAccidentName());

                //车辆的涉水信息
                CommUtils.setText(textViewCarInWadeOutSide, _evaluateDetailItemBean.getWadeName());

                //车辆中间的评估备注信息
                CommUtils.setText(textViewEditInputRemark, _evaluateDetailItemBean.getRemark());

                //用户上传的附件信息
                npl_item_moment_photos_in_detail_middle.setDelegate(new BGANinePhotoLayout.Delegate() {

                    @Override
                    public void onClickNinePhotoItem(BGANinePhotoLayout ninePhotoLayout, View view, int position, String model, List<String> models) {
                        //点击九宫格
                        //点击九宫格,查看大图
                        mCurrentClickNpl = ninePhotoLayout;

                        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.TIRAMISU) {
                            photoPreviewWrapper();
                        } else {
                            photoPreviewIntentXXPermissions();
                        }

                    }

                    @Override
                    public void onClickExpand(BGANinePhotoLayout ninePhotoLayout, View view, int position, String model, List<String> models) {
                        //点击展开的
                        ninePhotoLayout.setIsExpand(true);
                        ninePhotoLayout.flushItems();
                    }

                });

                //从服务器获取的图片的链接，有null空路径的情况出现；
                //List<String> receptionImgs_server = _evaluateDetailItemBean.getReceptionImgs();
                //防止里边有null的链接出现，所以做一层过滤；
                List<String> receptionImgs_filter_after_result = new ArrayList<>();
                if (_evaluateDetailItemBean.getReceptionImgs() != null && !_evaluateDetailItemBean.getReceptionImgs().isEmpty()) {
                    for (String itemHttpUrl : _evaluateDetailItemBean.getReceptionImgs()) {
                        if (!TextUtils.isEmpty(itemHttpUrl) && !itemHttpUrl.contains(Parameterkey.null_value)) {
                            receptionImgs_filter_after_result.add(itemHttpUrl);
                        }
                    }
                }

                npl_item_moment_photos_in_detail_middle.setData((ArrayList<String>) receptionImgs_filter_after_result);


                //----------------------------------------------------------------------------------------------------
                //底部的评估价格信息
                //价格本身
                String priceType = _evaluateDetailItemBean.getPriceType();

                if (TextUtils.equals(priceType, EvalutePriceType.PRICETYPE_ONE_SINGLE.getIndex())) {

                    CommUtils.setText(textViewEditViewFormWhereName, EvalutePriceType.PRICETYPE_ONE_SINGLE.getValue());

                    BigDecimal minPrice = _evaluateDetailItemBean.getMinPrice();
                    if (minPrice != null) {
                        CommUtils.setText(editViewPriceEvaluate, MMKV.defaultMMKV().decodeString(ConstantSign.P_CURRENCYSYMBOL) + minPrice.toString() + StringUtils.getString(R.string.unitmoney));
                    } else {
                        CommUtils.setText(editViewPriceEvaluate, MMKV.defaultMMKV().decodeString(ConstantSign.P_CURRENCYSYMBOL) + CommUtils.formatComma2BigDecimal(0.00).toString() + StringUtils.getString(R.string.unitmoney));
                    }

                } else if (TextUtils.equals(priceType, EvalutePriceType.PRICETYPE_TWO_RANGE.getIndex())) {

                    CommUtils.setText(textViewEditViewFormWhereName, EvalutePriceType.PRICETYPE_TWO_RANGE.getValue());

                    BigDecimal minPrice = _evaluateDetailItemBean.getMinPrice();
                    BigDecimal maxPrice = _evaluateDetailItemBean.getMaxPrice();
                    if (minPrice != null && maxPrice != null) {
                        CommUtils.setText(editViewPriceEvaluate, MMKV.defaultMMKV().decodeString(ConstantSign.P_CURRENCYSYMBOL) + minPrice.toString() + StringUtils.getString(R.string.unitmoney) + "-" + MMKV.defaultMMKV().decodeString(ConstantSign.P_CURRENCYSYMBOL) + maxPrice.toString() + StringUtils.getString(R.string.unitmoney));
                    } else if (minPrice != null && maxPrice == null) {
                        CommUtils.setText(editViewPriceEvaluate, MMKV.defaultMMKV().decodeString(ConstantSign.P_CURRENCYSYMBOL) + minPrice.toString() + StringUtils.getString(R.string.unitmoney) + "-" + MMKV.defaultMMKV().decodeString(ConstantSign.P_CURRENCYSYMBOL) + CommUtils.formatComma2BigDecimal(0.00).toString() + StringUtils.getString(R.string.unitmoney));
                    } else if (minPrice == null && maxPrice != null) {
                        CommUtils.setText(editViewPriceEvaluate, MMKV.defaultMMKV().decodeString(ConstantSign.P_CURRENCYSYMBOL) + CommUtils.formatComma2BigDecimal(0.00).toString() + StringUtils.getString(R.string.unitmoney) + "-" + maxPrice.toString() + StringUtils.getString(R.string.unitmoney));
                    } else if (minPrice == null && maxPrice == null) {
                        CommUtils.setText(editViewPriceEvaluate, MMKV.defaultMMKV().decodeString(ConstantSign.P_CURRENCYSYMBOL) + CommUtils.formatComma2BigDecimal(0.00).toString() + StringUtils.getString(R.string.unitmoney) + "-" + CommUtils.formatComma2BigDecimal(0.00).toString() + StringUtils.getString(R.string.unitmoney));
                    }
                }

                //评估的备注信息
                CommUtils.setText(textVieweEvaluatePriceBottom, _evaluateDetailItemBean.getPriceRemark());

            }
        });

    }

    /**
     * 图片预览，兼容6.0动态权限
     */
    @AfterPermissionGranted(PRC_PHOTO_PREVIEW)
    private void photoPreviewWrapper() {
        if (mCurrentClickNpl == null) {
            return;
        }

        String[] perms = {Manifest.permission.WRITE_EXTERNAL_STORAGE};

        if (EasyPermissions.hasPermissions(this, perms)) {

            CommTools.photoPreviewIntent(mActivityInstance, mActivityInstance, mCurrentClickNpl);

        } else {
            //EasyPermissions.requestPermissions(this, "图片预览需要以下权限:\n\n1.访问设备上的照片", PRC_PHOTO_PREVIEW, perms);
            EasyPermissions.requestPermissions(this, StringUtils.getString(R.string.imagenicelook), PRC_PHOTO_PREVIEW, perms);
        }

    }

    private void photoPreviewIntentXXPermissions() {

        if (!XXPermissions.isGranted(CarEvaluateDetailActivity.this, com.hjq.permissions.Permission.READ_MEDIA_IMAGES)) {

            CommUtils.checkMaterialDialog(materialDialog);

            materialDialog = CommUtils.authorityRequest(mActivityInstance, ConstantSign.MATERIALDIALOG_AUTHORITY_CONTENT_ALBUM, new AuthorityCallbackListener() {
                @Override
                public void doSomeThing() {

                    CommUtils.checkMaterialDialog(materialDialog);

                    XXPermissions.with(CarEvaluateDetailActivity.this)
                            // 适配分区存储应该这样写
                            //.permission(Permission.Group.STORAGE)
                            // 不适配分区存储应该这样写
//                    .permission(com.hjq.permissions.Permission.CAMERA)//
                            .permission(com.hjq.permissions.Permission.READ_MEDIA_IMAGES)//
//                  .permission(com.hjq.permissions.Permission.READ_MEDIA_VIDEO)//
//                  .permission(com.hjq.permissions.Permission.READ_MEDIA_AUDIO)//
                            //).permission(com.hjq.permissions.Permission.MANAGE_EXTERNAL_STORAGE
                            .interceptor(new PermissionInterceptor())
                            .request(new OnPermissionCallback() {

                                @Override
                                public void onGranted(@NonNull List<String> permissions, boolean allGranted) {

                                    if (!allGranted) {
                                        return;
                                    }

                                    Toaster.show(String.format(getString(R.string.demo_obtain_permission_success_hint),
                                            PermissionNameConvert.getPermissionString(CarEvaluateDetailActivity.this, permissions)));

                                    CommTools.photoPreviewIntent(mActivityInstance, mActivityInstance, mCurrentClickNpl);

                                }
                            });

                }
            });

        } else {

            CommTools.photoPreviewIntent(mActivityInstance, mActivityInstance, mCurrentClickNpl);

        }

    }

//    private void photoPreviewIntent() {
//
////        File downloadDir = new File(Environment.getExternalStorageDirectory(), ConstantSign.BGAPHOTOPICKERDOWNLOAD);
//        File downloadDir = new File(PathUtils.getExternalAppFilesPath(), ConstantSign.BGAPHOTOPICKERDOWNLOAD);
//
//        BGAPhotoPreviewActivity.IntentBuilder photoPreviewIntentBuilder = new BGAPhotoPreviewActivity.IntentBuilder(this);
//
//        if (true) {
//            // 保存图片的目录，如果传 null，则没有保存图片功能
//            photoPreviewIntentBuilder.saveImgDir(downloadDir);
//        }
//
//        if (mCurrentClickNpl.getItemCount() == 1) {
//            // 预览单张图片
//            photoPreviewIntentBuilder.previewPhoto(mCurrentClickNpl.getCurrentClickItem());
//
//        } else if (mCurrentClickNpl.getItemCount() > 1) {
//            // 预览多张图片
//            photoPreviewIntentBuilder.previewPhotos(mCurrentClickNpl.getData())
//                    .currentPosition(mCurrentClickNpl.getCurrentClickItemPosition()); // 当前预览图片的索引
//        }
//
//        startActivity(photoPreviewIntentBuilder.build());
//
//    }

    @Override
    public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
        super.onRequestPermissionsResult(requestCode, permissions, grantResults);
        EasyPermissions.onRequestPermissionsResult(requestCode, permissions, grantResults, this);
    }

    @Override
    public void onPermissionsGranted(int requestCode, List<String> perms) {
    }

    @Override
    public void onPermissionsDenied(int requestCode, List<String> perms) {
        if (requestCode == PRC_PHOTO_PREVIEW) {
            //Toast.makeText(this, "您拒绝了「图片预览」所需要的相关权限!", Toast.LENGTH_SHORT).show();
            Toast.makeText(this, StringUtils.getString(R.string.image_preview), Toast.LENGTH_SHORT).show();
        }
    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void onEventMainThreadInEvaluateDetail(EventCarEvaluateDetail eventCarEvaluateDetail) {

        if (eventCarEvaluateDetail != null) {

            if (eventCarEvaluateDetail.getMessage() == ExtraValue.EVENTBUS_EVENT_TO_REFRESH_EVALUATE_CAR_DETAIL) {

                gainDatas();

            }
        }

    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        EventBus.getDefault().unregister(this);
    }

    @Override
    protected void methodBack() {

        if (ActivityUtils.isActivityAlive(this)) {
            ActivityUtils.finishActivity(this);
        }

    }

    @Override
    public void processExtraData() {

        //use the data received here
        Bundle bundle = this.getIntent().getExtras();

        if (bundle != null) {

//            LogUtils.d(ConstantSign.LOGCAT_NOMAL + extra_jumpfrom_where);

            //主要是携带 条目的id 获取详情用
            extra_evalute_current_item_bean = bundle.getParcelable(ExtraKey.EXTRA_EVALUTE_CURRENT_ITEM_BEAN);

        }
    }
}